﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Meqs.Entity;
using Meqs.Logic.Interface;

namespace Meqs.Logic.Implement
{
    public class TeacherEvalDetailLogic : CommonLogic<TeacherEvalDetail, int>, ITeacherEvalDetailLogic
    {
        private ISchoolInfoLogic _schoolLogic;
        public TeacherEvalDetailLogic(ISchoolInfoLogic schoolLogic)
        {
            _schoolLogic = schoolLogic;
        }
        #region Implementation of ICommonLogic<TeacherEvalDetail, int>

        /// <summary>
        /// 创建对象
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Create(TeacherEvalDetail entity)
        {
            return CreateObject(entity);
        }

        /// <summary>
        /// 更新对象
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Update(TeacherEvalDetail entity)
        {
            return UpdateObject(entity);
        }

        /// <summary>
        /// 删除对象
        /// </summary>
        /// <param name="entityId"></param>
        /// <returns></returns>
        public int Delete(int entityId)
        {
            return DeleteObject(entityId);
        }

        /// <summary>
        /// 删除所有对象
        /// </summary>
        /// <returns></returns>
        public int DeleteAll()
        {
            return DeleteAllObject();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entityId"></param>
        /// <returns></returns>
        public TeacherEvalDetail FindById(int entityId)
        {
            return FindObjectById(entityId);
        }

        /// <summary>
        /// 检索对象数量
        /// </summary>
        /// <returns></returns>
        public int FindCount()
        {
            return FindObjectByCount();
        }

        /// <summary>
        /// 检索对象
        /// </summary>
        public IList<TeacherEvalDetail> FindAll()
        {
            return FindAllObject();
        }

        /// <summary>
        /// 检索对象数量
        /// </summary>
        /// <returns></returns>
        public int FindCount(Hashtable table)
        {
            return FindObjectByCount(table);
        }

        /// <summary>
        /// 检索对象
        /// </summary>
        public IList<TeacherEvalDetail> FindAll(Hashtable table)
        {
            return FindObject(table);
        }

        #endregion

        /// <summary>
        /// 获取教师在学分管理下指定月份内的评估明细
        /// </summary>
        /// <param name="teacherID">教师id</param>
        /// <param name="reportType">
        ///  报表类型
        /// 1:日报
        /// 2:周报
        /// 3:月报
        /// </param>
        /// <param name="year">报表年度</param>
        /// <param name="month">报表月度</param>
        /// <param name="schoolYear">学年，不填为当前学年</param>
        /// <param name="term">学期，不填为当前学期</param>
        /// <param name="schoolMark">学校编号</param>
        /// <returns></returns>
        public IList<TeacherInputEntity> GetTeacherInputEntityByMonth(int historyId, int teacherID, int reportType, int year, int month, int? schoolYear, int? term, string schoolMark)
        {
            if (schoolYear == null || schoolYear < 0 || term == null || term < 0)
            {
                SchoolInfo school = _schoolLogic.FindBySchoolMark(schoolMark);
                schoolYear = school.SchoolYear;
                term = school.SchoolTerm;
            }
            Hashtable ht = new Hashtable();
            ht.Add("historyId", historyId);
            ht.Add("SchoolMark", schoolMark);
            ht.Add("TeacherID", teacherID);
            ht.Add("ReportDate", new DateTime(year, month, 1));
            ht.Add("ReportType", reportType);
            ht.Add("SchoolYear", schoolYear);
            ht.Add("Term", term);
            return FindCustomer<TeacherInputEntity>("TeacherEvalDetail.GetTeacherInputEntityByMonth", ht);
        }

        /// <summary>
        /// 获取教师在学分管理下指定月份内的评估明细
        /// </summary>
        /// <param name="teacherID">教师id</param>
        /// <param name="reportType">
        ///  报表类型
        /// 1:日报
        /// 2:周报
        /// 3:月报
        /// </param>
        /// <param name="year">报表年度</param>
        /// <param name="month">报表月度</param>
        /// <param name="schoolYear">学年，不填为当前学年</param>
        /// <param name="term">学期，不填为当前学期</param>
        /// <param name="schoolMark">学校编号</param>
        /// <returns></returns>
        public IList<TeacherInputEntity> GetTeacherInputEntityByMonth(int historyId,int teacherID,int managerId, int reportType, int year, int month, int? schoolYear, int? term, string schoolMark)
        {
            if (schoolYear == null || schoolYear < 0 || term == null || term < 0)
            {
                SchoolInfo school = _schoolLogic.FindBySchoolMark(schoolMark);
                schoolYear = school.SchoolYear;
                term = school.SchoolTerm;
            }
            Hashtable ht = new Hashtable();
            ht.Add("historyId", historyId);
            ht.Add("SchoolMark", schoolMark);
            ht.Add("TeacherID", teacherID);
            ht.Add("ReportDate", new DateTime(year, month, 1));
            ht.Add("ReportType", reportType);
            ht.Add("SchoolYear", schoolYear);
            ht.Add("Term", term);
            ht.Add("managerId", managerId);
            ht.Add("managerId2", managerId);
            return FindCustomer<TeacherInputEntity>("TeacherEvalDetail.GetTeacherInputEntityByMonth", ht);
        }


        /// <summary>
        /// 获取教师在学分管理下指定学期内的评估明细
        /// </summary>
        /// <param name="teacherID">教师id</param>
        /// <param name="reportType">
        ///  报表类型
        /// 1:日报
        /// 2:周报
        /// 3:月报
        /// </param>
        /// <param name="year">报表年度</param>
        /// <param name="month">报表月度</param>
        /// <param name="schoolYear">学年，不填为当前学年</param>
        /// <param name="term">学期，不填为当前学期</param>
        /// <param name="schoolMark">学校编号</param>
        /// <returns></returns>
        public IList<TeacherInputEntity> GetTeacherInputEntityByTerm(int historyId,int teacherID,int managerId, int year, int month, int? schoolYear, int? term, string schoolMark)
        {
            if (schoolYear == null || schoolYear < 0 || term == null || term < 0)
            {
                SchoolInfo school = _schoolLogic.FindBySchoolMark(schoolMark);
                schoolYear = school.SchoolYear;
                term = school.SchoolTerm;
            }
            Hashtable ht = new Hashtable();
            ht.Add("historyId", historyId);
            ht.Add("SchoolMark", schoolMark);
            ht.Add("TeacherID", teacherID);
          //  ht.Add("ReportDate", new DateTime(year, month, 1));
          //  ht.Add("ReportType", reportType);
            ht.Add("SchoolYear", schoolYear);
            ht.Add("Term", term);
            ht.Add("managerId", managerId);
            ht.Add("managerId2", managerId);
            return FindCustomer<TeacherInputEntity>("TeacherEvalDetail.GetTeacherInputEntityByTerm", ht);
        }
        /// <summary>
        /// 获取教师在学分管理下指定学期内的评估明细
        /// </summary>
        /// <param name="teacherID">教师id</param>
        /// <param name="reportType">
        ///  报表类型
        /// 1:日报
        /// 2:周报
        /// 3:月报
        /// </param>
        /// <param name="year">报表年度</param>
        /// <param name="month">报表月度</param>
        /// <param name="schoolYear">学年，不填为当前学年</param>
        /// <param name="term">学期，不填为当前学期</param>
        /// <param name="schoolMark">学校编号</param>
        /// <returns></returns>
        public IList<TeacherInputEntity> GetTeacherInputEntityByTerm(int historyId, int teacherID, int year, int month, int? schoolYear, int? term, string schoolMark)
        {
            if (schoolYear == null || schoolYear < 0 || term == null || term < 0)
            {
                SchoolInfo school = _schoolLogic.FindBySchoolMark(schoolMark);
                schoolYear = school.SchoolYear;
                term = school.SchoolTerm;
            }
            Hashtable ht = new Hashtable();
            ht.Add("historyId", historyId);
            ht.Add("SchoolMark", schoolMark);
            ht.Add("TeacherID", teacherID);
            ht.Add("SchoolYear", schoolYear);
            ht.Add("Term", term);
            return FindCustomer<TeacherInputEntity>("TeacherEvalDetail.GetTeacherInputEntityByTerm", ht);
        }


        public IList<TeacherInputEntity> GetTeacherInputEntityByStudent(int historyId, int teacherID, int managerId, int year, int month, int? schoolYear, int? term, string schoolMark)
        {
            if (schoolYear == null || schoolYear < 0 || term == null || term < 0)
            {
                SchoolInfo school = _schoolLogic.FindBySchoolMark(schoolMark);
                schoolYear = school.SchoolYear;
                term = school.SchoolTerm;
            }
            Hashtable ht = new Hashtable();
            ht.Add("historyId", historyId);
            ht.Add("SchoolMark", schoolMark);
            ht.Add("TeacherID", teacherID);
            ht.Add("SchoolYear", schoolYear);
            ht.Add("Term", term);
            ht.Add("managerId", managerId);
            return FindCustomer<TeacherInputEntity>("TeacherEvalDetail.GetTeacherInputEntityByStudent", ht);
        }

        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="stuCauseEvalDetail"></param>
        /// <param name="schoolMark"></param>
        /// <returns></returns>
        public int InsertTeacherEvalDetail(TeacherEvalDetail teacherEvalDetail, string schoolMark)
        {
            Hashtable ht = new Hashtable();
            ht.Add("TeacherEvalDetail", teacherEvalDetail);
            ht.Add("SchoolMark", schoolMark);
            return (int)InsertCustomer("TeacherEvalDetail.InsertTeacherEvalDetail", ht);
        }

    }
}
